#ifndef HEFENG_WEATHER_DATA_HPP
#define HEFENG_WEATHER_DATA_HPP

#include <vector>
#include "content/basic_provider.hpp"
#include "content/generated_data.hpp"
#include "content/image.hpp"
#include "content/view_base.hpp"
#include "utils/safe_value.hpp"

class IconManager;

PCLASS(HefengData,Fields;WhiteListMethods) {
    GENERATED_GET_DATA(HefengData);
public:
    HefengData(std::string apikey, std::string *city_id, IconManager *mmg);
    ~HefengData();

     bindable_base::binddata_t post_get(const std::string &key, bool *handled);

    // update weather
    void do_update_weather();
private:
    PMETA(Skipped) std::string apikey;
    PMETA(Skipped) std::string *current_city_id;
    PMETA(Skipped) IconManager *icons_;

    PMETA(Key:"real_time_weather") ui_view *realtime_;
    PMETA(Key:"find_city") ui_view *find_;

    // data fields for find city
    std::string search_keyword;
    u32 selected_result;
    basic_data<u32> result_count;
    struct CityResult { std::string display; std::string id; };
    PMETA(Skipped) std::vector<CityResult> city_results;
    
    // operations
    void do_search();
    void do_choose_city();

    // data fields for weather update
    struct RealtimeWeatherInfo{
        std::string temp{"N/A"};
        std::string feelsLike{"N/A"};
        std::string icon{"N/A"};
        std::string text{"N/A"};
        std::string wind{"N/A"}; // windDir + windScale, windSpeed
        std::string humidity{"N/A"};
    };
    PMETA(Skipped) RealtimeWeatherInfo weather_info;
    ImageContent *weather_icon{nullptr};
};

PSTRUCT (Test,All) {
    GENERATED_GET_DATA (Test);

public:
    u32 a;
    u8  b;
    f64 c;

    void hello_world();
};

#endif /* HEFENG_WEATHER_DATA_HPP */
